/*
 * @Descripttion: GGB
 * @version: 1.0
 * @Author: GGB
 * @Date: 2021-08-16 14:52:56
 * @LastEditors: GGB
 * @LastEditTime: 2021-08-16 15:47:43
 */
import 'package:flutter/material.dart';
import 'package:flutter_data_center/controller/common_controller.dart';
import 'package:get/get.dart';
import 'package:scroll_to_index/scroll_to_index.dart';

import '../../../constants.dart';

class MenuList extends StatelessWidget {
  const MenuList({Key key, this.currentIndex, this.onChange, this.controller})
      : super(key: key);
  final int currentIndex;
  final ValueChanged<int> onChange;
  final AutoScrollController controller;

  @override
  Widget build(BuildContext context) => GetBuilder<CommonController>(
        builder: (_controller) => Center(
          child: Container(
            alignment: Alignment(0.5, 0.5),
            height: 30,
            width: double.infinity,
            child: ListView(
              scrollDirection: Axis.horizontal,
              controller: controller,
              children: List.generate(
                  _controller.floors.length,
                  (index) => AutoScrollTag(
                        key: ValueKey(index),
                        controller: controller,
                        index: index,
                        child: buildMenu(index, _controller),
                      )).toList(),
            ),
          ),
        ),
      );
  Column buildMenu(int index, CommonController _controller) {
    return Column(
      crossAxisAlignment: CrossAxisAlignment.center,
      mainAxisAlignment: MainAxisAlignment.center,
      children: [
        InkWell(
          onTap: () => onChange(index),
          child: Container(
            padding: EdgeInsets.symmetric(horizontal: defaultPadding / 2),
            child: Text(
              _controller.floors[index].name,
              style: TextStyle(
                color: Colors.white,
                fontSize: 18,
                fontWeight: FontWeight.w700,
              ),
            ),
          ),
        ),
        SizedBox(height: 5),
        index == currentIndex
            ? Container(
                height: 3,
                width: 30,
                decoration: BoxDecoration(
                  color: Colors.blue,
                  borderRadius: BorderRadius.circular(defaultRadius),
                ))
            : SizedBox(
                height: 3,
                width: 20,
              ),
      ],
    );
  }
}
